import Mock from 'mockjs';
import setupMock, {
  successResponseWrap,
  failResponseWrap,
} from '@/utils/setup-mock';
import { MockParams } from '@/types/mock';
import { data as jsonData } from './projectJsonData';
import type { DataEnum } from '@/api/project/project.d';

setupMock({
    setup() {
        // 列表查询及列表数据
        Mock.mock(new RegExp('/api/anno/task/search'), (data: MockParams) => {
            const { 
                department, 
                keyword, 
                status, 
                uses, 
                companyId, 
                label, 
                target, 
                annoUserId, 
                beginDate, 
                endDate, 
                page, 
                pageSize 
            } = JSON.parse(data.body || '{}');
            if (department) {
                const departmentEnum: DataEnum = {
                    '1': '放射科',
                    '2': '病理科',
                    '3': '内科'
                }
                const newRes = jsonData.filter(item => item.department === departmentEnum[department]);
                return successResponseWrap({
                    total: newRes.length,
                    pages: newRes.length <= 10 ? 1 : 10,
                    list: newRes
                });
            }
            if (keyword) {
                const newRes = jsonData.filter(item => item.id === keyword);
                return successResponseWrap({
                    total: newRes.length,
                    pages: newRes.length <= 10 ? 1 : 10,
                    list: newRes
                });
            }
            return successResponseWrap({
                total: jsonData.length,
                pages: jsonData.length <= 10 ? 1 : 10,
                list: jsonData
            })
        })

        // 列表发布、终结改变
        Mock.mock(new RegExp('/api/anno/task/status/edit'), (data: MockParams) => {
            const { id, status } = JSON.parse(data.body || '{}');
            return successResponseWrap(null);
        })
    }
})